import e from "./kv_motion";
import t from "./event_center";
import n from "./event";
import r from "./touch_event";
import i from "./audio_ctrl";
import Cubic from "./cubic";

export default class StarKv extends e {
  starName = null;
  soundEffect = null;
  initialize() {
    let e = this;
    e.starName != null &&
      ((e.soundEffect = new i("sounds/" + e.starName + ".mp3")),
      e.soundEffect.loop(!1),
      e.initWithURL("views/" + e.starName + ".xml"));
  }
  playBox = null;
  huMovie = null;
  gfMovie = null;
  btnBack = null;
  normalBox = null;
  btnStart = null;
  onViewControllerPrepared() {
    let e = this;
    (e.playBox = e.view().subViewByName("play_box")),
      (e.huMovie = e.playBox.subViewByName("hu_movie")),
      (e.gfMovie = e.playBox.subViewByName("gf_movie")),
      (e.btnBack = e.playBox.subViewByName("btn_back")),
      (e.normalBox = e.view().subViewByName("normal_box")),
      (e.btnStart = e.normalBox.subViewByName("btn_start")),
      t.addListener(e.btnStart, e, r.CLICK, e.playMotion),
      t.addListener(e.btnBack, e, r.CLICK, e.stopMotion),
      t.addListener(e.huMovie, e, n.END, e.onHUMovieEnd);
  }
  onViewAddToStage() {
    let e = this;
    e.prepared &&
      ((e.isPlaying = !1),
      e.btnStart.normalStateView.play(0),
      e.normalBox.alpha(1),
      e.normalBox.stopAnimation(),
      e.view().empty(),
      e.view().addSubView(e.normalBox));
  }
  onViewRemoveFromStage() {
    let e = this;
    e.prepared && e.soundEffect != null && e.soundEffect.pause();
  }
  isPlaying = !1;
  playMotion() {
    let e = this;
    e.isPlaying == 0 &&
      ((e.isPlaying = !0),
      e.btnBack.stopAnimation(),
      e.btnBack.visible(!1),
      e.huMovie.goToAndStop(0),
      e.gfMovie.goToAndStop(0),
      e.gfMovie.stopAnimation(),
      e.gfMovie.visible(!1),
      e.view().insertSubViewAt(e.playBox, 0),
      e.btnStart.normalStateView.currentTime(0),
      e.btnStart.normalStateView.pause(),
      e.normalBox.animate(
        1,
        {
          alpha: 0,
        },
        Cubic.easeIn,
        null,
        function () {
          e.soundEffect != null && e.soundEffect.play(0),
            e.normalBox.remove(),
            e.huMovie.play();
        }
      ));
  }
  stopMotion() {
    let e = this;
    e.isPlaying &&
      ((e.isPlaying = !1),
      e.btnBack.normalStateView.currentTime(0),
      e.btnBack.normalStateView.pause(),
      e.normalBox.alpha(0),
      e.view().addSubView(e.normalBox),
      e.normalBox.animate(
        1,
        {
          alpha: 1,
        },
        Cubic.easeOut,
        null,
        function () {
          e.btnStart.normalStateView.play(0), e.playBox.remove();
        }
      ),
      e.soundEffect != null && e.soundEffect.pause());
  }
  onHUMovieEnd() {
    let e = this;
    e.gfMovie.alpha(0),
      e.gfMovie.visible(!0),
      e.gfMovie.animate(
        0.5,
        {
          alpha: 1,
        },
        Cubic.easeOut,
        null,
        function () {
          e.gfMovie.play(),
            setTimeout(function () {
              e.btnBack.alpha(0),
                e.btnBack.visible(!0),
                e.btnBack.normalStateView.currentTime(0),
                e.btnBack.normalStateView.pause(),
                e.btnBack.animate(
                  0.5,
                  {
                    alpha: 1,
                  },
                  Cubic.easeOut,
                  null,
                  function () {
                    e.btnBack.normalStateView.play(0);
                  }
                );
            }, 2400);
        }
      );
  }
}
